package cn.itrigger.dynamic.sql.where.render;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author admin
 * @date 2018/9/21
 **/
public class WhereClauseProvider {

    private String whereClause;

    private Map<String, Object> parameters;

    public Map<String, Object> getParameters() {
        return Collections.unmodifiableMap(parameters);
    }

    public String getWhereClause() {
        return whereClause;
    }

    protected WhereClauseProvider(Builder builder) {
        this.whereClause = Objects.requireNonNull(builder.whereClause);
        this.parameters = Objects.requireNonNull(builder.parameters);
    }

    public static Builder withWhereClause(String whereClause) {
        return new Builder().withWhereClause(whereClause);
    }

    public static class Builder {
        private String whereClause;
        private Map<String, Object> parameters = new HashMap<>();

        public Builder withWhereClause(String whereClause) {
            this.whereClause = whereClause;
            return this;
        }

        public Builder withParameters(Map<String,Object> parameters) {
            this.parameters = parameters;
            return this;
        }

        public WhereClauseProvider build() {
            return new WhereClauseProvider(this);
        }
    }
}
